package com.ruoyi.linkage.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.ruoyi.linkage.Vo.LinkageStrategyVo;
import com.ruoyi.linkage.domain.LinkageAction;
import com.ruoyi.linkage.domain.LinkageStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.linkage.mapper.LinkageAuthorizeMapper;
import com.ruoyi.linkage.domain.LinkageAuthorize;
import com.ruoyi.linkage.service.ILinkageAuthorizeService;

/**
 * 联动授权配置Service业务层处理
 *
 * @author pengjie
 * @date 2023-12-20
 */
@Service
public class LinkageAuthorizeServiceImpl implements ILinkageAuthorizeService
{
    @Autowired
    private LinkageAuthorizeMapper linkageAuthorizeMapper;

    /**
     * 查询联动授权配置
     *
     * @param id 联动授权配置主键
     * @return 联动授权配置
     */
    @Override
    public LinkageAuthorize selectLinkageAuthorizeById(Long id)
    {
        return linkageAuthorizeMapper.selectLinkageAuthorizeById(id);
    }

    @Override
    public PageInfo<LinkageAuthorize> selectPage(LinkageStrategyVo linkageStrategyVo) {
        IPage<LinkageAuthorize> page = new Page<>(Integer.parseInt(linkageStrategyVo.getPageNum()),Integer.parseInt(linkageStrategyVo.getPageSize()));
        String str=linkageStrategyVo.getColumn();
        //修改驼峰命名为数据库列格式
        StringBuffer buf=new StringBuffer();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (Character.isUpperCase(c)) {
                buf.append('_');
                buf.append(Character.toLowerCase(c));
            }else {
                buf.append(c);
            }
        }
        linkageStrategyVo.setColumn(buf.toString());
        List<LinkageAuthorize> list=linkageAuthorizeMapper.selectListOrder(linkageStrategyVo);
        PageInfo<LinkageAuthorize> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 查询联动授权配置列表
     *
     * @param linkageAuthorize 联动授权配置
     * @return 联动授权配置
     */
    @Override
    public List<LinkageAuthorize> selectLinkageAuthorizeList(LinkageAuthorize linkageAuthorize)
    {
        return linkageAuthorizeMapper.selectLinkageAuthorizeList(linkageAuthorize);
    }

    /**
     * 新增联动授权配置
     *
     * @param linkageAuthorize 联动授权配置
     * @return 结果
     */
    @Override
    public int insertLinkageAuthorize(LinkageAuthorize linkageAuthorize)
    {
        return linkageAuthorizeMapper.insertLinkageAuthorize(linkageAuthorize);
    }

    /**
     * 修改联动授权配置
     *
     * @param linkageAuthorize 联动授权配置
     * @return 结果
     */
    @Override
    public int updateLinkageAuthorize(LinkageAuthorize linkageAuthorize)
    {
        return linkageAuthorizeMapper.updateLinkageAuthorize(linkageAuthorize);
    }

    /**
     * 批量删除联动授权配置
     *
     * @param ids 需要删除的联动授权配置主键
     * @return 结果
     */
    @Override
    public int deleteLinkageAuthorizeByIds(Long[] ids)
    {
        return linkageAuthorizeMapper.deleteLinkageAuthorizeByIds(ids);
    }

    /**
     * 删除联动授权配置信息
     *
     * @param id 联动授权配置主键
     * @return 结果
     */
    @Override
    public int deleteLinkageAuthorizeById(Long id)
    {
        return linkageAuthorizeMapper.deleteLinkageAuthorizeById(id);
    }
}
